<?php
// +----------------------------------------------------------------------
// | title: 标题注释
// +----------------------------------------------------------------------
// | Author: TZ.Leong
// +----------------------------------------------------------------------
// | Date: 2020/8/18 17:04
// +----------------------------------------------------------------------

namespace app\single\command;


use think\Command;
use think\Db;

class StatHook extends Command
{
    protected function execute($input, $output)
    {
        $day = date("Ymd", strtotime("-1 days"));
        $list = Db::table(config("database.game") . ".role")
            ->alias("rh")
            ->leftJoin([ "role_pay_total" => "rp"], "rp.role_id = rh.role_id")
//                ->where("current_hook", ">", 0)
            ->group("id")
            ->column("{$day} AS `day`, COUNT(rh.role_id) AS num, COUNT(rp.role_id) AS pay_num", "id AS level");
        echo "list.=======>" . json_encode($list);
        Db::table("c_stat_hook")->where("day", $day)->delete();
        Db::table("c_stat_hook")->insertAll($list);
    }
}